package interfaces

import (
	"gitee.com/captials-team/ubdframe/src/domain/dto"
	"gitee.com/captials-team/ubdframe/src/domain/dto/paginate"
	"gitee.com/captials-team/ubdframe/src/domain/models"
	"gorm.io/gorm"
)

type ItfAdminDao interface {
	Search(search *dto.SearchAdminParams, pa *paginate.Pager) ([]*models.Admin, *paginate.Pager, error)
	Query(id int64) (*models.Admin, error)
	QueryByAccount(string) (*models.Admin, error)
	QueryPassword(id int64) (string, string, error)
	Add(*models.Admin) (int64, error)
	AddCheckAccount(*models.Admin) (int64, error)
	Update(id int64, admin *models.Admin) (int64, error)
	Delete(id int64) (int64, error)

	ResetStatus(id int64, status int) (int64, error)
	ResetPassword(id int64, password string, noRoot bool) (int64, error)
	UpdateProInfo(id int64, admin *models.Admin) (int64, error)

	LoginNote(id int64, info *dto.LoginInfoParam) (int64, error) //登录记录

	Use(db *gorm.DB) ItfAdminDao //使用db

	ItfMigrate
	ItfGormDB
}

type ItfAdminLog interface {
	Search(search *dto.SearchAdminLogParams, p *paginate.Pager) ([]*models.AdminLog, *paginate.Pager, error)
	Add(log *models.AdminLog) (int64, error)

	Use(db *gorm.DB) ItfAdminLog

	ItfMigrate
	ItfGormDB
}

type ItfRbac interface {
	UserRoles(uid int64) ([]*models.RbacRole, error)
	UserPerms(uid int64) ([]*models.RbacPermission, error)
	UserPermIds(uid int64) ([]int64, error)

	//用户关联角色
	UserRoleIds(uid int64) ([]int64, error)
	UserRelateRoles(uid int64, roleIds []int64) error

	//角色相关
	SearchRoles(search *dto.SearchRbacRoleParams, pa *paginate.Pager) ([]*models.RbacRole, *paginate.Pager, error)
	Roles() ([]*models.RbacRole, error)
	QueryRole(id int64) (*models.RbacRole, error)
	AddRole(*models.RbacRole) (int64, error)
	UpdateRole(int64, *models.RbacRole) (int64, error)
	DeleteRole(id int64) error
	ResetRoleStatus(id int64, status int) (int64, error)

	//角色关联权限
	RolePermIds(roleId int64, moreRoles ...int64) ([]int64, error)
	RoleRelatePerms(roleId int64, permIds []int64) error

	//权限相关
	Perms() ([]*models.RbacPermission, error)
	QueryPerm(id int64) (*models.RbacPermission, error)
	AddPerm(*models.RbacPermission) (int64, error)
	BatchAddPerm(...*models.RbacPermission) (int64, error)
	UpdatePerm(int64, *models.RbacPermission) (int64, error)
	DeletePerm(id int64) error

	//simple相关
	SimplePerms() ([]*dto.RbacPermissionSimple, error)

	Use(db *gorm.DB) ItfRbac //使用db

	ItfMigrate
	ItfGormDB
}

// ItfRbacRole 角色相关
type ItfRbacRole interface {
	Search(search *dto.SearchRbacRoleParams, pa *paginate.Pager) ([]*models.RbacRole, *paginate.Pager, error)
	Query(id int64) (*models.RbacRole, error)
	Add(*models.RbacRole) (int64, error)
	Update(int64, *models.RbacRole) (int64, error)
	Delete(id int64) error
	ResetStatus(id int64, status int) (int64, error)

	Use(db *gorm.DB) ItfRbacRole //使用db

	ItfMigrate
	ItfGormDB
}

type ItfSettingDao interface {
	Set(key, value string) error
	Get(key string) (string, error)

	SetMulti(data map[string]string) error
	GetMulti(keys ...string) (map[string]string, error)

	Use(db *gorm.DB) ItfSettingDao

	ItfMigrate
	ItfGormDB
}

type ItfUser interface {
	Search(search *dto.SearchUserParams, pa *paginate.Pager) ([]*models.User, *paginate.Pager, error)
	Query(id int64) (*models.User, error)
	QueryByAccount(string) (*models.User, error)
	QueryByPhone(string) (*models.User, error)
	QueryByEmail(string) (*models.User, error)
	Add(*models.User) (int64, error)
	AddCheckAccount(u *models.User) (int64, error)
	Update(id int64, user *models.User) (int64, error)
	Delete(id int64) (int64, error)

	LoginNote(id int64, info *dto.LoginInfoParam) (int64, error) //登录记录

	ResetStatus(id int64, status int) (int64, error)
	ResetPassword(id int64, password string) (int64, error)
	UpdateProInfo(id int64, user *models.User) (int64, error)

	Use(db *gorm.DB) ItfUser //使用db

	ItfMigrate
	ItfGormDB
}

type ItfUserAccount interface {
	QueryByAccount(string) (*models.UserAccount, error)
	Add(*models.UserAccount) (int64, error)
	Delete(id int64) (int64, error)

	Use(db *gorm.DB) ItfUserAccount //使用db

	ItfMigrate
	ItfGormDB
}

type ItfUserThird interface {
	Search(search *dto.SearchUserThirdParams, pa *paginate.Pager) ([]*models.UserThird, *paginate.Pager, error)
	Query(id int64) (*models.UserThird, error)
	QueryByThirdId(thirdType string, thirdId string) (*models.UserThird, error)
	QueryByThirdUnionId(thirdType string, unionId string) (*models.UserThird, error)
	Add(*models.UserThird) (int64, error)
	Delete(id int64) (int64, error)

	Use(db *gorm.DB) ItfUserThird //使用db

	ItfMigrate
	ItfGormDB
}

// ItfVerifyCode 验证码相关db操作接口
type ItfVerifyCode interface {
	Query(id int64) (*models.VerifyCode, error)
	QueryByTarget(target string) (*models.VerifyCode, error)
	Verify(target string, code string) (bool, error)
	Add(code *models.VerifyCode) (int64, error)
	Delete(id int64) (int64, error)

	Use(db *gorm.DB) ItfVerifyCode //使用db

	ItfMigrate
	ItfGormDB
}

// ItfUserLoginRecord 用户登录记录
type ItfUserLoginRecord interface {
	Search(search *dto.SearchLoginRecordParams, pa *paginate.Pager) ([]*models.UserLoginRecord, *paginate.Pager, error)
	Add(code *models.UserLoginRecord) (int64, error)

	Use(db *gorm.DB) ItfUserLoginRecord //使用db

	ItfMigrate
	ItfGormDB
}

// ItfUserGenericRecord 用户通用记录
type ItfUserGenericRecord interface {
	Search(search *dto.SearchGenericRecordParams, pa *paginate.Pager) ([]*models.UserGenericRecord, *paginate.Pager, error)
	Add(code *models.UserGenericRecord) (int64, error)
	Delete(id int64) (int64, error)

	Use(db *gorm.DB) ItfUserGenericRecord //使用db

	ItfMigrate
	ItfGormDB
}

// ItfBlockContentDao 块内容操作接口
type ItfBlockContentDao interface {
	Search(search *dto.SearchBlockContentParams, pa *paginate.Pager) ([]*models.BlockContent, *paginate.Pager, error)
	Query(id int64) (*models.BlockContent, error)
	QueryByCode(code string) (*models.BlockContent, error)
	Add(code *models.BlockContent) (int64, error)
	Update(id int64, up *models.BlockContent) (int64, error)
	Delete(id int64) (int64, error)

	Use(db *gorm.DB) ItfBlockContentDao //使用db

	ItfMigrate
	ItfGormDB
}

// ItfStatistical 统计相关
type ItfStatistical interface {
	Search(search *dto.SearchStatisticalParams, pa *paginate.Pager) ([]*models.Statistical, *paginate.Pager, error)
	Query(search *dto.SearchStatisticalParams) (*models.Statistical, error)
	Add(st *models.Statistical) (int64, error)
	Delete(id int64) (int64, error)
	DeleteByName(name, date string) (int64, error)

	Use(db *gorm.DB) ItfStatistical //使用db

	ItfMigrate
	ItfGormDB
}

// ItfOrganize 组织相关
type ItfOrganize interface {
	DBFacade[models.Organize]

	Delete(id int64) (int64, error)
	DeleteByPid(pid int64) (int64, error)
	ResetStatus(id int64, status int) (int64, error)

	Use(db *gorm.DB) ItfOrganize //使用db

	ItfMigrate
	ItfGormDB
}

// ItfOrganizeExtra 组织额外信息相关
type ItfOrganizeExtra interface {
	Search(orgId int64) ([]*models.OrganizeExtra, error)
	Add(models.OrganizeExtra) (int64, error)
	Clear(orgId int64) (int64, error)

	Use(db *gorm.DB) ItfOrganizeExtra //使用db

	ItfMigrate
	ItfGormDB
}

// ItfOrganizeRelate 组织关系相关
type ItfOrganizeRelate interface {
	DBFacade[models.OrganizeRelate]

	SearchParent(orgId int64, level int) ([]*models.OrganizeRelate, error)
	SearchChild(orgId int64, level int) ([]*models.OrganizeRelate, error)
	Add(models.OrganizeRelate) (int64, error)
	Clear(orgId int64) (int64, error)

	SqlForSearchChild(pid int64, level int) string

	Use(db *gorm.DB) ItfOrganizeRelate //使用db

	ItfMigrate
	ItfGormDB
}

// ItfMetricMetaDao 组织相关
type ItfMetricMetaDao interface {
	Search(search *dto.SearchMetricMetaDto, pa *paginate.Pager) ([]*models.Metrics, *paginate.Pager, error)
	Query(id int64) (*models.Metrics, error)
	QueryByName(name string) (*models.Metrics, error)
	Add(data *models.Metrics) (int64, error)
	Delete(id int64) (int64, error)

	Use(db *gorm.DB) ItfMetricMetaDao //使用db

	SubTableStrategy() func(int64) string //分表策略

	ItfMigrate
	ItfGormDB
}

// ItfMetricDataDao 组织相关
type ItfMetricDataDao interface {
	Search(search *dto.SearchMetricDataDto, pa *paginate.Pager) ([]*models.MetricData, *paginate.Pager, error)
	Query(metricId int64, timestamp int64) (*models.MetricData, error)
	QuerySum(req *dto.SearchMetricDataDto) (*models.MetricValueData, error)
	Add(data *models.MetricData) (int64, error)
	BatchAdd(...*models.MetricData) (int64, error)
	Delete(metricId int64, timestamp int64) (int64, error)
	Clean(dataDto dto.CleanMetricDataDto) (int64, error)
	CleanAll(dataDto dto.CleanMetricDataDto) (int64, error)

	Use(db *gorm.DB) ItfMetricDataDao //使用db

	InitTable(string) error
	InitSplitTable(string) error

	ItfMigrate
	ItfGormDB
}

// ItfMetricLatestDataDao 组织相关
type ItfMetricLatestDataDao interface {
	Query(metricId int64) (*models.MetricData, error)
	Add(data *models.MetricData) (int64, error)
	BatchAdd(...*models.MetricData) (int64, error)

	Use(db *gorm.DB) ItfMetricLatestDataDao //使用db

	ItfMigrate
	ItfGormDB
}

// ItfMetricStatDataDao 组织相关
type ItfMetricStatDataDao interface {
	Search(search *dto.SearchMetricStatDto, pa *paginate.Pager) ([]*models.MetricStatValueData, *paginate.Pager, error)
	Query(*dto.QueryMetricStatDto) (*models.MetricStatValueData, error)
	QuerySum(search *dto.SearchMetricStatDto) (*models.MetricValueData, error) //查询求和
	MergeAdd(...*models.MetricStatData) (int64, error)                         //合并添加
	CoverAdd(...*models.MetricStatData) (int64, error)                         //覆盖添加

	Use(db *gorm.DB) ItfMetricStatDataDao //使用db

	InitSplitTable(string) error

	ItfMigrate
	ItfGormDB
}
